/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.meego.common.oembed;

import com.meego.common.log.GA;
import com.meego.common.memcache.SpyMemcache;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author TueHM
 */
public class OEmbedCA {

    private static SpyMemcache client;
    public static boolean isCacheSupport;

    static {
        try {
            client = SpyMemcache.getInstance("cache.oembed");
            isCacheSupport = client.isCacheSupport;
        } catch (Exception ex) {
            GA.cache.error("Initialize Cache fail", ex);
        }
    }

    public static boolean insert(String key, OembedResponse value) throws Exception {
        return client.add(key, value);
    }

    public static boolean update(String key, OembedResponse value) throws Exception {
        return client.set(key, value);
    }

    public static boolean delete(String key) throws Exception {
        return client.delete(key);
    }

    public static OembedResponse get(String key) {
        Object obj = null;
        try {
            obj = client.get(key);
        } catch (Exception ex) {
            Logger.getLogger(OEmbedCA.class.getName()).log(Level.SEVERE, null, ex);
        }
        return obj == null ? null : (OembedResponse) obj;
    }
}
